<?php
namespace app\common\service\user;



use app\admin\model\user\User;
use app\admin\model\user\UserBank;
use app\api\controller\user\BankBind;
use app\common\service\BaseService;
use app\common\service\lib\Bank;
use app\common\service\lib\sms\Sms;
use app\common\service\lib\sms\SmsFactory;
use app\validate\BankValidate;
use think\exception\ValidateException;


class UserBankService extends BaseService
{

    /**
     * Author:Yingbo Sun
     * 绑定银行卡
     * @param $post
     * @return array
     */
    public static function bindBank($post)
    {
        try {
            validate(BankValidate::class)->check([
                'credit_card_numbers' => $post['credit_card_numbers'],
                'identity_card' => $post['identity_card'],
                'name' => $post['name'],
            ]);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return self::fail($e->getError());
        }
        //银行卡校验             银行卡号                        身份证号                姓名
        $body = Bank::verifyBank($post['credit_card_numbers'],$post['identity_card'],$post['name'],$post['phone']);
        if ($body['status'] == '01'){
            $post['bank_company'] = $body['bank'];
            $post['bank_name'] = $body['cardName'];
            $post['bank_type'] = $body['cardType'];
            $data = UserBank::create($post);
            if($data){
                return self::success('银行卡绑定成功');
            }else{
                return self::fail('银行卡绑定失败');
            }
        }else{
            return self::fail('验证不通过');
        }
    }
}